import JSEncrypt from "jsencrypt/bin/jsencrypt.min";

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKUO9jLz/1O2i2pCwSWq8ZqCDP+yO8WLcMd3Y8mrcvUwRkkwaHHrm8WIKUAx++pj9SI3tR6X0lB5JUK/vPfdzoDmCo9LNbJnwWaDYJjAmtqFgKdbyaQgOp0ux24pjLhQ3iB2zrZuyLKWRV5vy3Mo6SuIVVffnXhWifpcU0dA8zmLAgMBAAECgYAa2lJHe9agIeSQhwexPxxLTLkcqDx9KPBSIyRC3Pe41/+3TH7Reck/26UKYpdfTJ/Gz1VSAtUebncXYuY1VQqRPvJU8RoT6xWV1rkhD2s6KKXwAFl1pyfSBSTsiV5BVTkHMblY2jKdceYnbsDTkpSKgOpUSTp/EGkfrvnsrAYuUQJBANNrpL/k68a6bGkB8vUmR5goAQ8E0G8O+3RQ4NZCjOlrA4cUIrkMZjQ/4faa/6rGq2NfkjmkZXD5X7WOrARBPU8CQQDH3LjO20rBQuKQt+A5IOIqL8Ska45JdSv1K40Hu9GFdEFqEscacslq0aO7mJnT5cam+x8fQVah8l9kH86GVskFAkAEQh7HXq0BC7AzTT6/gU3f2q5qxwYLtpmJ9jcRGbYM3YLsrZMldwJ3+vFqLiUII4hAMCSZ1J3WcK9k0MLWMxoxAkEApGhOYmOESByUMcYAnh4NzfRDh5muj4DiqyirN9xpy6VJlk9iF8CrLcLMNKqgh+3xjzTuchCWilvN2phLlLjZXQJAGqLBOENsqAVNDZZDL2T1I9xb9lCPsTMARhyL1xiRvwzMew0k9GFsSRj7zSJBXhK4bc1tC8gaAyjMQmy6skotww==";

const privateKey =
  "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n" +
  "7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n" +
  "PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n" +
  "kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n" +
  "cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n" +
  "DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n" +
  "YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n" +
  "UP8iWi1Qw0Y=";

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey); // 设置私钥
  return encryptor.decrypt(txt); // 对数据进行解密
}
